﻿Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Enterprise
Imports System.Drawing.Font
Imports DMC.Land.User
Imports Microsoft.Reporting.WinForms
Public Class frmNhomChu
    Public dt As New DataTable()
    Private strMaHoSoCapGCN As String = ""
    Private conn As New SqlConnection
    Private strMaDVHC As String = ""
    Private strConnection As String = ""
    Private DTChinh As New DataTable
    Public arr As New ArrayList
    Public strMaChu As String = ""    
    Public Property ChuSudung() As String
        Get
            Return strMaChu
        End Get
        Set(ByVal value As String)
            strMaChu = value
        End Set
    End Property
    Public Property DB() As DataTable
        Get
            Return DTChinh
        End Get
        Set(ByVal value As DataTable)
            DTChinh = value
        End Set
    End Property
    Public Property DBByNhomChu() As DataTable
        Get
            Return dt
        End Get
        Set(ByVal value As DataTable)
            dt = value
        End Set
    End Property   
    Public Sub LoadReport()

        Me.DataGridView1.DataSource = DTChinh
        DataGridView1.Columns("SoTT").Visible = False

        DataGridView1.Columns("NhomMaChu").Visible = True
        DataGridView1.Columns("ChuDat").HeaderText = "Chủ Sử Dụng Đất"
        DataGridView1.Columns("ChuDat").Width = 500
    End Sub
    Private Sub frmNhomChu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub DataGridView1_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
        If e.RowIndex >= 0 Then

            'Hiển thị thông tin Chủ sử dụng
            ChiTietChu.Text = DataGridView1.Rows(e.RowIndex).Cells("ChuDat").Value.ToString()

        End If
        
    End Sub

    Private Sub btnHuy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHuy.Click
        For Each row As DataGridViewRow In DataGridView1.Rows
            If row.Cells("check").Value = True Then
                row.Cells("check").Value = False
            End If
        Next
    End Sub

    Private Sub btndongy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndongy.Click
        arr.Clear()
        Dim MC As String = ""
        For i As Integer = 0 To DataGridView1.Rows.Count - 1
            If (DataGridView1.Rows(i).Cells("check").Value = True) Then
                arr.Add(DataGridView1.Rows(i).Cells("NhomMaChu").Value.ToString())
            End If
        Next

        For Each machu As Object In arr
            MC = MC.Trim + "*" + machu.ToString.Trim
        Next
        strMaChu = MC
        SetTableSoDiaChinhByNhomMaChu()
        'Me.Hide()
        Me.Close()
    End Sub
    Public Sub SetTableSoDiaChinhByNhomMaChu()
        'dt = DTChinh.Clone()
        Dim ctr As New ctrInSo
        'ctr.DataTable1 = DTChinh.Clone()
        dt = DTChinh.Clone()
        For Each row As DataGridViewRow In DataGridView1.Rows
            If (row.Cells("check").Value = True) Then
                Dim dtrow As DataRow = dt.NewRow()
                dtrow(0) = row.Cells("SoTT").Value.ToString()
                dtrow(1) = row.Cells("NhomMaChu").Value.ToString()
                dtrow(2) = row.Cells("ChuDat").Value.ToString()
                dtrow(3) = row.Cells("BienDongChoChuDat").Value.ToString()
                dt.Rows.Add(dtrow)
            End If
        Next
        ctr.Get_straa = "1234567890"
    End Sub
End Class